# MakeBy: LiuBoyuan
from api.commands.interface import command_interface
from config.basic import container_tasks
from framework.modfuncexecute import ModFuncExecute


class command_dispatch:
    def __init__(self, command: str):
        """
        命令分发器
        :param command:
        """
        self.command = command
        self.splite = command.split(" ")


        self.command_name, *self.command_args = self.splite
        self.command_handler = container_tasks.get(self.command_name)

    def dispath(self) -> command_interface:
        if self.command_handler is None: return None

        mod_func_execute = ModFuncExecute(function_path=self.command_handler)

        self.command_handler = mod_func_execute.funtionRun(self.splite)  # 实例化指定的函数
        self.command_handler.command_dispatch = self  # 将 分发器 动态绑定给 执行器

        return self.command_handler
